﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Globalization;

namespace devtm.Configuration.Models
{

    public enum TypeParametre
    {
        None,
        Section,
        MethodParameter, 
        StringName
    }

    [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
    public class CustomDesignerAction : Attribute
    {


        public CustomDesignerAction()
        {
            TypeAction = EnumAction.Edit;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CustomDesignerAction"/> class.
        /// </summary>
        /// <param name="type">type de la classe contenant l'action.</param>
        /// <param name="actionName">Nom de la methode contenant l'action.</param>
        public CustomDesignerAction(Type type, string actionName)
        {

            this.Type = type;
            this.ActionName = actionName;

            MethodInfo = this.Type.GetMethod(ActionName);

            if (MethodInfo == null)
                throw new Exception(string.Format(CultureInfo.CurrentCulture,
                    ResourceConfiguration.DonTExistIn, ActionName, type.Name));

            if (MethodInfo.GetParameters().Count() > 1)
                throw new Exception(string.Format(CultureInfo.CurrentCulture,
                    ResourceConfiguration.CanTContains0Or1Parameter, ActionName, type.Name));

        }

        /// <summary>
        /// type de la classe contenant l'action
        /// </summary>
        public Type Type { get; set; }

        /// <summary>
        /// Nom de la methode contenant l'action
        /// </summary>
        public string ActionName { get; set; }

        public string DisplayName  { get; set; }
        /// <summary>
        /// Nom de la fonction renvoyant vrai ou faux pour afficher l'action.
        /// </summary>
        public string ViewFor { get; set; }

        public MethodInfo MethodInfo { get; set; }

        public TypeParametre Parametre {get; set; }

        public EnumAction TypeAction { get; set; }
    }

}
